package com.examination.controller.utils;

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import javax.activation.*;

/**
 * @Auther: GongXl
 * @Date: 022 17:20
 * @Description:
 */
@WebServlet("/sendm")
public class SendEmail extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String par = req.getParameter("par1");
        // 调用两个 ServletContext.log 方法
        ServletContext context = getServletContext( );

        if (par == null || par.equals(""))
            // 通过 Throwable 参数记录版本
            context.log("No message received:",
                    new IllegalStateException("Missing parameter"));
        else
            context.log("Here is the visitor's message: " + par);

        resp.setContentType("text/html;charset=UTF-8");
        java.io.PrintWriter out = resp.getWriter( );
        String title = "Context Log";
        String docType = "<!DOCTYPE html> \n";
        out.println(docType +
                "<html>\n" +
                "<head><title>" + title + "</title></head>\n" +
                "<body bgcolor=\"#f0f0f0\">\n" +
                "<h1 align=\"center\">" + title + "</h1>\n" +
                "<h2 align=\"center\">Messages sent</h2>\n" +
                "</body></html>");
    }
}